import Page from '../../../../vue-common/models/Page';
import BaseModule from './base-module'
import Ajax from '../../lib/ajax'

class MemberModule extends BaseModule{
    state={
        memberMap: {}
    }
    actions={
        async getMemberProfiles(context, ids){
            var temp = [];
            ids.forEach(elem => {
                if(context.state.memberMap[elem] && context.state.memberMap[elem].loaded) {
                    return;
                }else {
                    context.state.memberMap[elem] = {
                        id: elem,
                        userName: '',
                        head: '',
                        level: 0,
                        loaded: false
                    }
                    temp.push(elem);
                }
            });
            if(temp.length == 0) return;
            var response = await Ajax.post('/api/services/app/Member/GetProfiles', { ids: temp });
            if(response.data.success) {
                response.data.result.forEach(elem => {
                    var item = context.state.memberMap[elem.id];// Object.assign({ loaded: true }, elem);
                    item.loaded = true;
                    item.userName = elem.userName;
                    item.head = elem.head;
                    item.level = elem.level;
                });
            }
        },
    };
    mutations={
    }
}

const memberModule = new MemberModule();
export default memberModule;